package com.example.day2.busi.my;

import androidx.lifecycle.MutableLiveData;

import com.example.day2.entity.IconResult;
import com.example.day2.entity.UpDateAddress;
import com.example.day2.entity.UpDateBrith;
import com.example.day2.entity.UpDateSexResult;
import com.example.day2.entity.VideoResult;
import com.example.day2.mvvm.base.BaseRepo;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MultipartBody;

public class MyRepo extends BaseRepo {
    public void getLives(MutableLiveData<VideoResult> success,MutableLiveData<String> fail){
        apiService.getLives()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<VideoResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(VideoResult videoResult) {
                        success.setValue(videoResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void getSex(String sex,MutableLiveData<UpDateSexResult> success,MutableLiveData<String> fail){
        apiService.getSex(sex)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<UpDateSexResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(UpDateSexResult upDateSexResult) {
                        success.setValue(upDateSexResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void getIcon(MultipartBody.Part part, MutableLiveData<IconResult> success, MutableLiveData<String> fail){
        apiService.getIcon(part)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<IconResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(IconResult iconResult) {
                        success.setValue(iconResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void getBrith(String brith, MutableLiveData<UpDateBrith> success, MutableLiveData<String> fail){
        apiService.getBrith(brith)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<UpDateBrith>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(UpDateBrith upDateBrith) {
                        success.setValue(upDateBrith);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void getAddress(String brith, MutableLiveData<UpDateAddress> success, MutableLiveData<String> fail){
        apiService.getAddress(brith)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<UpDateAddress>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(UpDateAddress upDateAddress) {
                        success.setValue(upDateAddress);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
